package com.neuedu.controller;


import com.alibaba.fastjson2.JSONObject;
import com.neuedu.base.R;
import com.neuedu.model.ShouFei;
import com.neuedu.service.ShouFeiService;
import com.neuedu.service.impl.ShouFeiServiceImpl;
import com.neuedu.vo.PageVO;
import java.util.Map;

/**
 * @author dell
 */
public class ShouFeiController {
    private ShouFeiService shouFeiService=new ShouFeiServiceImpl();

    public R page(JSONObject jsonObject){
        String minDate = jsonObject.getString("minDate");
        String maxDate = jsonObject.getString("maxDate");
        String likeName = jsonObject.getString("likeName");
        Integer pageNo=jsonObject.getInteger("pageNo");
        Integer pageSize=jsonObject.getInteger("pageSize");
        PageVO<ShouFei> pageVO = shouFeiService.selectPage(minDate, maxDate, likeName, pageNo, pageSize);

        return R.ok("分页数据查询成功").setData(pageVO);
    }

    public static final String FILE_PATH="E:\\java07";


    //编辑
    public R query(Map<String,String[]> map){
        Integer id = Integer.parseInt(map.get("id")[0]);

        ShouFei shouFei = shouFeiService.queryShouFei(id);

        return R.ok("详细信息查询成功").setData(shouFei);
    }


    public R del(Map<String,String[]> map){
        String [] idsStr = map.get("id");
        Integer [] ids=new Integer[idsStr.length];
        for (int i = 0; i < ids.length; i++) {
            ids[i]=Integer.parseInt(idsStr[i]);
        }
        //调用service层，把ids传入，service帮我删去数据。
        int result = shouFeiService.delShouFei(ids);
        if(result>0){
            return R.ok("删除成功");
        }else{
            return R.error("删除失败");
        }
    }

    public R save(JSONObject jsonObject){
        Integer id=jsonObject.getInteger("id");
        String suoshuxiaoqu = jsonObject.getString("suoshuxiaoqu");
        String mingcheng = jsonObject.getString("mingcheng");
        Integer xiaoquid = jsonObject.getInteger("xiaoquid");
        ShouFei shouFei=new ShouFei();


        shouFei.setId(id);
        shouFei.setSuoshuxiaoqu(suoshuxiaoqu);
        shouFei.setMingcheng(mingcheng);
        shouFei.setXiaoquid(xiaoquid);
        //service方法的保存
        int result = shouFeiService.saveShouFei(shouFei);
        if(result>0){
            return R.ok("更新成功");
        }else{
            return R.error("更新失败");
        }

    }


    public R add(JSONObject jsonObject){
        Integer xiaoquid = jsonObject.getInteger("xiaoquid");
        String suoshuxiaoqu = jsonObject.getString("suoshuxiaoqu");
        String mingcheng = jsonObject.getString("mingcheng");
        ShouFei shouFei=new ShouFei();

        shouFei.setXiaoquid(xiaoquid);
        shouFei.setSuoshuxiaoqu(suoshuxiaoqu);
        shouFei.setMingcheng(mingcheng);
        //service方法的保存
        int result = shouFeiService.addShouFei(shouFei);
        if(result>0){
            return R.ok("更新成功");
        }else{
            return R.error("更新失败");
        }

    }


}
